package com.foreveross.proxyip.core.pools.validate;

import java.util.Random;

import com.foreveross.proxyip.core.BaseCode;
import com.foreveross.proxyip.core.redis.PiRedisExecption;
import com.foreveross.proxyip.infra.conf.PropertyUtils;
import com.foreveross.proxyip.infra.conf.proxyip.ProxyIpPropertiesLoader;
import com.foreveross.proxyip.util.Config;

public class PublicTestProxyIp extends TestProxyIp {
	
	private String [] connectUrls;
	public PublicTestProxyIp(String poolSign) throws PiRedisExecption{
		super(poolSign);
		setConfig();
		
	}
		
		/**
		 * 随机获取配置中的一个公共池验证url
		 * @return
		 */
		public String getConnectUrl(){
			int randSign = new Random().nextInt(connectUrls.length);
			return connectUrls[randSign];
		}

		@Override
		public void setConfig() throws NumberFormatException, PiRedisExecption {
			
			Integer publicConnectTimeout = Integer.parseInt( BaseCode.getValue("PUBLIC_CONNECT_TIMEOUT"));
			
			Integer publicSoTimeout = Integer.parseInt( BaseCode.getValue("PUBLIC_SO_TIMEOUT")); 
			
			Integer maxUsedCount = Integer.parseInt( BaseCode.getValue("PUBLIC_MAX_USED_COUNT")); 
			
			Integer valiSeparTime = Integer.parseInt( BaseCode.getValue("PUBLIC_IP_VALI_SEPAR_TIME")); 
			
			
			Long ipAvailTime = Long.parseLong(BaseCode.getValue("PUBLIC_IP_AVAIL_TIME")); 
			
			Integer proxyValiType = Integer.parseInt(BaseCode.getValue("PUBLIC_PROXY_VALI_TYPE")); 
			connectUrls = BaseCode.getValue("PUBLIC_POOLS_VALIDATE_URLS").split(",");
			super.connectTimeout = publicConnectTimeout;
			super.soTimeout= publicSoTimeout;
			super.maxUsedCount = maxUsedCount;
			super.valiSeparTime = valiSeparTime;
			super.ipAvailTime = ipAvailTime;
			super.proxyValiType = proxyValiType;
			String speedGradesStr = BaseCode.getValue("SPEED_GRADE");
			this.setSpeedGrades(speedGradesStr);
		}
		
		

		@Override
		public boolean isValidate() {
			// TODO Auto-generated method stub
			return true;
		}


}
